package com.moss.web;

import com.moss.common.annotation.AuthorizationPerm;
import com.moss.common.core.BaseController;
import com.moss.common.domain.AjaxResult;
import com.moss.common.domain.TreeEntity;
import com.moss.common.entity.SysGoodsCategoryEntity;
import com.moss.common.entity.SysGoodsEntity;
import com.moss.system.service.GoodsCategoryService;
import com.moss.system.service.GoodsService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("goods")
public class GoodsController extends BaseController {


    @Resource
    GoodsService goodsService;

    @Resource
    GoodsCategoryService goodsCategoryService;


    @GetMapping("/categoryTree")
    public AjaxResult<List<TreeEntity>> categoryTree(){
        List<SysGoodsCategoryEntity> list = goodsCategoryService.selectList();
        return AjaxResult.success(goodsCategoryService.buildTree(list));
    }

    @GetMapping("/list")
    public AjaxResult<List<SysGoodsEntity>> goodsList(SysGoodsEntity goods){
        startPage();
        List<SysGoodsEntity> goodsList = goodsService.selectList(goods);
        return AjaxResult.success(goodsList,new PageInfo<>(goodsList).getTotal());
    }


//    @GetMapping("/getCategoryList")
//    public AjaxResult<List<DetectionGoodsCategoryVO>> getCategoryList(){
//        List<DetectionGoodsCategoryVO> list = goodsService.getGoodsCategoryList();
//        return AjaxResult.success(list);
//    }
//
//
//    @GetMapping("/getGoodsList")
//    @AuthorizationPerm("goods:query")
//    public AjaxResult<List<DetectionGoodsVO>> getGoodsList(@RequestParam String searchInfo,
//                                                           @RequestParam Long parentId,
//                                                           @RequestParam(defaultValue = "1") Integer pageNum,
//                                                           @RequestParam(defaultValue = "10") Integer pageSize){
//        PageHelper.startPage(pageNum,pageSize);
//        List<DetectionGoodsVO> list = goodsService.getGoodsList(parentId,searchInfo);
//        return AjaxResult.success(list,new PageInfo<>(list).getTotal());
//    }


}
